﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'proc_cm_SwapSiteNodeDisplayOrder')
BEGIN
    PRINT 'Dropping Procedure proc_cm_SwapSiteNodeDisplayOrder'
    DROP  Procedure  proc_cm_SwapSiteNodeDisplayOrder
END
GO

PRINT 'Creating Procedure proc_cm_SwapSiteNodeDisplayOrder'
GO

CREATE PROCEDURE [dbo].[proc_cm_SwapSiteNodeDisplayOrder]
	@pNodeId1 uniqueidentifier
	, @pNodeId2 uniqueidentifier
AS
BEGIN
	DECLARE @vDisplayOrderNum1 INT, @vDisplayOrderNum2 INT

	SELECT @vDisplayOrderNum1 = [display_order_num]
	FROM [dbo].[tbl_sitemap] (nolock)
	WHERE [node_id] = @pNodeId1

	SELECT @vDisplayOrderNum2 = [display_order_num]
	FROM [dbo].[tbl_sitemap] (nolock)
	WHERE [node_id] = @pNodeId2

	UPDATE [dbo].[tbl_sitemap] 
	SET [display_order_num] = @vDisplayOrderNum2
	WHERE [node_id] = @pNodeId1

	UPDATE [dbo].[tbl_sitemap] 
	SET [display_order_num] = @vDisplayOrderNum1
	WHERE [node_id] = @pNodeId2
END
GO

GRANT EXEC ON dbo.proc_cm_SwapSiteNodeDisplayOrder TO PUBLIC
GO
